<template>
    <el-form inline  class="demo-form-inline">
        <el-form-item label="时间范围">
            <el-date-picker
                    v-model="query.dateRange"
                    type="datetimerange"
                    range-separator="到"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
            />
        </el-form-item>
        <el-form-item>
            <el-button type="primary" plain  activity @click="queryLog">查询</el-button>
            <el-button type="primary" plain  activity @click="reset">重置</el-button>
        </el-form-item>
    </el-form>
    <el-divider style="margin: 12px 0"/>
    <el-table ref="table" border  v-loading="loading"  :data="data.tableData" header-cell-class-name="headerClass">
        <el-table-column align="center" type="index"  label="序号" width="100px" />
        <el-table-column align="center"  prop="username" label="用户名" />
        <el-table-column align="center"  prop="nickName" label="昵称" />
        <el-table-column align="center"  prop="ipAddress" show-overflow-tooltip label="ip地址" />
        <el-table-column align="center"  prop="loginTime" label="登录时间" >
            <template #default="scope">
                {{moment(scope.row.loginTime).format("yyyy-MM-DD HH:mm:ss")}}
            </template>
        </el-table-column>
    </el-table>
        <el-pagination
                style="display: flex;align-items:center;justify-content:center;"
                v-model:currentPage="query.currentPage"
                v-model:page-size="query.pageSize"
                :page-sizes="[10, 20, 30]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="query.total"
                @size-change="queryLog"
                @current-change="queryLog"
        />
</template>

<script setup>
    import request from '@/utils/request.js'
    import { ElMessage } from 'element-plus'
    import {ref,  reactive, onMounted} from 'vue'
    import moment from 'moment'

    let data = reactive({
        open:false,
        tableData:[],
        type:"",
        id:"",
    });
    let loading = ref(true)

    let query = reactive({dateRange:[],currentPage:1,pageSize:10,total:0})
    onMounted(() => {
        queryLog()
    })
    function queryLog(){
        query.beginTime = query.dateRange[0]
        query.endTime = query.dateRange[1]
        request.post("/api/loginLog/getLoginLogs", query).then(resp => {
            data.tableData = resp.records
            query.total = resp.total
            loading.value = false
        })
    }
    function reset (){
        query.dateRange = []
    }
</script>
<style lang="css" scoped>
    .address {overflow:hidden;white-space:nowrap;word-wrap:break-word;text-overflow:"ellipsis";}
    .head {background-color: #9561cc}
    [v-cloak]{
        display: none  !important;
    }
</style>